package com.hui.service;

import com.hui.dao.mapper.ResourceMapper;
import com.hui.entity.Resource;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Service
public class ResourceService {
    @Autowired
    private ResourceMapper resourceMapper;
    private static final Logger logger = Logger.getLogger(ResourceService.class);

    /**
     * 获取用户所有权限的名字
     */
    public Set<String> loadPermissionsByUsername(String username) {
        List<Resource> resList=resourceMapper.loadPermissionsByUsername(username);
        Set<String> set=new HashSet<String>();
        StringBuffer sb=new StringBuffer();
        for(Resource resource:resList){
            if(resource.getPermission()!=null&& resource.getPermission().length() > 0){
                set.add(resource.getPermission());
                sb.append("["+resource.getPermission()+"]");
            }
        }
        logger.info("[用户权限]："+sb);
        return set;
    }
    /**
     * 获取到所有权限的对象
     */
    public List<Resource> getUserAllResource(String userName){
        return resourceMapper.loadPermissionsByUsername(userName);
    }

}
